From 5dc5381fcc8a6c3bb5bbb869cdb6b704fffb79e6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 22 Jul 2014 08:33:47 -0700 Subject: [PATCH] Use a hash for -C metadata instead of a string This ends up serving the same purpose, but a critical change is that it canonicalizes the relevant git url (if one is used) to ensure that the same package from two slightly different locations is always built the same way. Sadly I'm not quite sure how to add a test for this as it involves using remote git urls which are unusable during tests. --- src/cargo/core/package_id.rs | 6 ++--- src/cargo/ops/cargo_rustc/fingerprint.rs | 2 +- tests/test_cargo_compile.rs | 32 ++++++++++++------------ tests/test_cargo_compile_git_deps.rs | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index b5d8d9436..51ce421d2 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -118,11 +118,11 @@ impl PackageId { } pub fn generate_metadata(&self) -> Metadata { - let metadata = format!("{}:-:{}:-:{}", self.name, self.version, self.source_id); - let extra_filename = short_hash( + let metadata = short_hash( &(self.name.as_slice(), self.version.to_string(), &self.source_id)); + let extra_filename = format!("-{}", metadata); - Metadata { metadata: metadata, extra_filename: format!("-{}", extra_filename) } + Metadata { metadata: metadata, extra_filename: extra_filename } } } diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 763a120d3..c72fa7c73 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -71,7 +71,7 @@ pub fn prepare(cx: &mut Context, pkg: &Package, fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target]) -> CargoResult<(bool, String)> { let new_pkg_fingerprint = format!("{}{}", cx.rustc_version, - try!(dep.get_fingerprint(cx.config))); + try!(dep.get_fingerprint(cx.config))); let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets)); diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 5a5529bc3..eabf75ac4 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -990,12 +990,12 @@ test!(verbose_build { let output = p.cargo_process("cargo-build").arg("-v") .exec_with_output().assert(); let out = str::from_utf8(output.output.as_slice()).assert(); - let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15); - let hash = hash.slice_to(17); + let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16); + let hash = hash.slice_to(16); assert_eq!(out, format!("\ {} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ - -C metadata=test:-:0.0.0:-:file:{dir} \ - -C extra-filename={hash} \ + -C metadata={hash} \ + -C extra-filename=-{hash} \ --out-dir {dir}{sep}target \ -L {dir}{sep}target \ -L {dir}{sep}target{sep}deps` @@ -1020,14 +1020,14 @@ test!(verbose_release_build { let output = p.cargo_process("cargo-build").arg("-v").arg("--release") .exec_with_output().assert(); let out = str::from_utf8(output.output.as_slice()).assert(); - let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15); - let hash = hash.slice_to(17); + let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16); + let hash = hash.slice_to(16); assert_eq!(out, format!("\ {} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 3 \ --cfg ndebug \ - -C metadata=test:-:0.0.0:-:file:{dir} \ - -C extra-filename={hash} \ + -C metadata={hash} \ + -C extra-filename=-{hash} \ --out-dir {dir}{sep}target{sep}release \ -L {dir}{sep}target{sep}release \ -L {dir}{sep}target{sep}release{sep}deps` @@ -1068,30 +1068,30 @@ test!(verbose_release_build_deps { .exec_with_output().assert(); let out = str::from_utf8(output.output.as_slice()).assert(); let pos1 = out.find_str("extra-filename=").unwrap(); - let hash1 = out.slice_from(pos1 + 15).slice_to(17); + let hash1 = out.slice_from(pos1 + 16).slice_to(16); let pos2 = out.slice_from(pos1 + 10).find_str("extra-filename=").unwrap(); - let hash2 = out.slice_from(pos1 + 10 + pos2 + 15).slice_to(17); + let hash2 = out.slice_from(pos1 + 10 + pos2 + 16).slice_to(16); assert_eq!(out, format!("\ {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \ --crate-type dylib --crate-type rlib \ --opt-level 3 \ --cfg ndebug \ - -C metadata=foo:-:0.0.0:-:file:{dir} \ - -C extra-filename={hash1} \ + -C metadata={hash1} \ + -C extra-filename=-{hash1} \ --out-dir {dir}{sep}target{sep}release{sep}deps \ -L {dir}{sep}target{sep}release{sep}deps \ -L {dir}{sep}target{sep}release{sep}deps` {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \ --opt-level 3 \ --cfg ndebug \ - -C metadata=test:-:0.0.0:-:file:{dir} \ - -C extra-filename={hash2} \ + -C metadata={hash2} \ + -C extra-filename=-{hash2} \ --out-dir {dir}{sep}target{sep}release \ -L {dir}{sep}target{sep}release \ -L {dir}{sep}target{sep}release{sep}deps \ --extern foo={dir}{sep}target{sep}release{sep}deps/\ - {prefix}foo{hash1}{suffix} \ - --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo{hash1}.rlib` + {prefix}foo-{hash1}{suffix} \ + --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-{hash1}.rlib` {compiling} foo v0.0.0 (file:{dir}) {compiling} test v0.0.0 (file:{dir})\n", running = RUNNING, diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 9af4b5004..3a0f52b2c 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1,4 +1,4 @@ -use std::io::{File, TempDir}; +use std::io::File; use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths}; use support::{cargo_dir}; -- 2.30.2